package com.mjk.manager.magicapi.servlet;

import com.mjk.manager.magicapi.core.core.context.MagicUser;
import com.mjk.manager.magicapi.core.core.servlet.MagicHttpServletRequest;
import com.mjk.manager.magicapi.core.core.servlet.MagicHttpServletResponse;
import com.mjk.manager.magicapi.core.core.servlet.MagicRequestContextHolder;
import org.springframework.web.multipart.MultipartResolver;

public class MagicJakartaRequestContextHolder implements MagicRequestContextHolder {

    /**
     * 当前登入的用户名称
     */
    private MagicUser currentUser;

    private final MultipartResolver multipartResolver;

    public MagicJakartaRequestContextHolder(MultipartResolver multipartResolver) {
        this.multipartResolver = multipartResolver;
    }

    @Override
    public MagicHttpServletRequest getRequest() {
        return convert(servletRequestAttributes -> new MagicJakartaHttpServletRequest(servletRequestAttributes.getRequest(), multipartResolver));
    }

    @Override
    public MagicHttpServletResponse getResponse() {
        return convert(servletRequestAttributes -> new MagicJakartaHttpServletResponse(servletRequestAttributes.getResponse()));
    }

    public MagicUser getCurrentUser() {
        return this.currentUser;
    }

    public void setCurrentUser(MagicUser user) {
        this.currentUser = user;
    }
}
